#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct Point
{
	int x;
	int y;
	int z;
}point[50005];
int cmp(struct Point x, struct Point y)
{
	if(x.z < y.z) return 0;
	else return 1;
}
int main()
{
	freopen("in.txt", "r",stdin);
	int n;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d %d %d",&point[i].x,&point[i].y,&point[i].z);
	}
	sort(point,point+n,cmp);
	double ans = 0;
	for(int i = 0; i < n-1; i++)
	{
		ans += sqrt((point[i].x - point[i+1].x)*(point[i].x - point[i+1].x)*1.0 + 
				(point[i].y - point[i+1].y) * (point[i].y - point[i+1].y)*1.0 + 
				(point[i].z - point[i+1].z)* (point[i].z - point[i+1].z)* 1.0);
	}
	printf("%.3lf",ans);
	return 0;
}
